<template>
	<view>
		<uni-forms :modelValue="formData">
			<uni-forms-item required label="手机号" name="phone">
				<uni-easyinput type="text" v-model="formData.phone" placeholder="请输入手机号" />
			</uni-forms-item>
			<uni-forms-item required label="姓名" name="name">
				<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item required name="posSn" label="机身号">
				<uni-easyinput type="text" v-model="formData.posSn" placeholder="请输入机身号" />
			</uni-forms-item>
			
		</uni-forms>
		<view class="btn-box">
			<button type="primary" @click="save" >添加</button>
		</view> 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData:{
					phone:'',
					name:'',
					posSn:''
				}
			}
		},
		methods: {
			save(){
				uni.navigateTo({
					url:'../index/index'
				})
				if(!this.formData.phone){
					uni.showToast({
						title:'手机号不能为空',
						icon:'error'
					})
					return
				}
				if(!this.formData.name){
					uni.showToast({
						title:'姓名不能为空',
						icon:'error'
					})
					return
				}
				if(!this.formData.posSn){
					uni.showToast({
						title:'机身号不能为空',
						icon:'error'
					})
					return
				}
				let that = this
				// this.formData.sign = this.getSignData(this.formData)	
				this.$http.post('https://jinyingke.xingke.cn/opay-business/redEnvelope/check',this.formData,res =>{
					if(res.code=='0000'){
						 that.$http.post('/user/save',that.formData,res=>{
							if(res.code == 200){
								setTimeout(() => {
									uni.navigateTo({
										url:'../index/index'
									})
								}, 500);
							}else{
								uni.showToast({
									title:'添加失败：'+res.msg,
									icon:'error'
								})
								return 
							}
						 })
					}else{
						uni.showToast({
							title:res.msg,
							icon:'error'
						})
						return
					}
				})
			}
		}
	}
</script>

<style>

</style>
